package com.example.deliveryapplication

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.deliveryapplication.entity.PlanItem
import com.example.deliveryapplication.entity.PlanItemWithClient
import com.example.deliveryapplication.entity.SelectString

class PlanChildAdapter(private val context: Context, private val mList: List<PlanItemWithClient>,private val listener:CallBack,private var canEdit:Boolean=false) : BaseRecyclerViewAdapter(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_plan_child_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.clientName.text=data.client.name
            holder.modelName.text="${data.model.type}-${data.model.name}"
            holder.count.text=data.planItem.num.handlerNull()
            holder.remarkTV.text=data.planItem.remark.handlerNull()
            holder.deleteTV.visibility=if(canEdit)View.VISIBLE else View.GONE
            holder.deleteTV.setOnClickListener {
                listener.onItemDelete(position, data)
            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val clientName: TextView = view.findViewById(R.id.clientName)
        val modelName: TextView = view.findViewById(R.id.modelName)
        val count: TextView = view.findViewById(R.id.count)
        val deleteTV:TextView= view.findViewById(R.id.deleteTV)
        val remarkTV:TextView=view.findViewById(R.id.remarkTV)

    }
    fun setCanEdit(canEdit:Boolean){
        this.canEdit=canEdit
    }
    interface CallBack {
        fun onItemDelete(position: Int,data:PlanItemWithClient)
    }

}